package com.ophiux.wechat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ophiux.wechat.mapper.OphiuxProblemMapper;
import com.ophiux.wechat.model.dto.OphiuxProblemAggregationDTO;
import com.ophiux.wechat.model.entity.OphiuxProblem;
import com.ophiux.wechat.model.entity.OphiuxProblemOptions;
import com.ophiux.wechat.service.OphiuxProblemOptionsService;
import com.ophiux.wechat.service.OphiuxProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:问题表接口实现层
 * @autor: hhl 
 * @date: 2023-07-19 14:55:40<br>
 */
@Service
public class OphiuxProblemServiceImpl extends ServiceImpl<OphiuxProblemMapper, OphiuxProblem> implements OphiuxProblemService {

    @Autowired
    OphiuxProblemOptionsService ophiuxProblemOptionsService;

    @Override
    public List<OphiuxProblemAggregationDTO> getProblemList(Integer useType) {
//        List<OphiuxProblem> problemList = this.list(new LambdaQueryWrapper<OphiuxProblem>().eq(OphiuxProblem::getUseType, useType));
        List<OphiuxProblemAggregationDTO> problemList = this.baseMapper.getProblemList(useType);
        for (OphiuxProblemAggregationDTO ophiuxProblem : problemList) {
            List<OphiuxProblemOptions> optionsList = ophiuxProblemOptionsService.list(new LambdaQueryWrapper<OphiuxProblemOptions>().eq(OphiuxProblemOptions::getProblemId, ophiuxProblem.getId()));
            if(optionsList!=null && optionsList.size()>0) {
                ophiuxProblem.setOptionsDTOList(optionsList);
            }
        }
        return problemList;
    }
}